import 'package:enterprise_v6_app/app/components/custom_modele/custom_field.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_picker_photo.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/list.dart';
import 'package:enterprise_v6_app/app/modules/application/education/personal_profile/real_name/name_controller.dart';

const _blue = Color(0xFF5C6DFF);

final _style = TextStyle(fontSize: 12.w);

class EducationProfileNameView extends StatelessWidget {
  EducationProfileNameView({super.key});

  final controller = Get.put(EducationProfileNameController());

  @override
  Widget build(BuildContext context) {
    return Obx(() => controller.isEditing.value ? _buildEditing() : _buildDisplay());
  }

  Widget _buildEditing() {
    final children = <Widget>[
      CustomField(
        title: '职工姓名',
        right: CustomField.input(controller: controller.nameCtrl),
        isRequired: true,
      ),
      const CustomField(
        title: '证件类型',
        right: Text('身份证'),
        isRequired: true,
      ),
      CustomField(
        title: '证件号码',
        right: CustomField.input(controller: controller.idCtrl),
        isRequired: true,
      ),
      CustomField(
        title: '证件正面',
        bottom: Container(
          margin: EdgeInsets.only(top: 10.w),
          alignment: Alignment.centerLeft,
          height: 90.w,
          width: 144.w,
          color: _blue,
        ),
        isRequired: true,
      ),
      CustomField(
        title: '证件背面',
        bottom: Container(
          margin: EdgeInsets.only(top: 10.w),
          alignment: Alignment.centerLeft,
          height: 90.w,
          width: 144.w,
          color: _blue,
        ),
        isRequired: true,
      ),
    ].joinWith(Divider(
      height: 1.w,
      color: const Color(0xffECEEF3),
    ));
    children.add(_buildAcknowledge());
    return ListView(
      children: [
        Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(10.w),
          ),
          child: Column(
            children: children,
          ),
        ),
        AppGaps.vGap10,
        _buildBottom(),
      ],
    );
  }

  Widget _buildDisplay() {
    final children = <Widget>[
      CustomField(
        title: '真实姓名',
        right: CustomField.input(
          controller: controller.nameCtrl,
          onChanged: (p0) {
            controller.onSaveChanges();
          },
        ),
      ),
      const CustomField(
        title: '证件',
        right: Text('居民身份证'),
      ),
      CustomField(
        title: '证件号码',
        right: CustomField.input(
          controller: controller.idCtrl,
          hide: true,
          onChanged: (p0) {
            controller.onSaveChanges();
          },
        ),
      ),
      CustomPickerPhoto(
        title: '证件正面',
        maxCount: 1,
        imagesList: controller.idPicFrontList,
        titleTextStyle: TextStyle(
          fontSize: 14.sp,
          height: 1.2,
          fontWeight: FontWeight.w500,
          color: const Color(0xff262F38),
        ),
      ).paddingSymmetric(horizontal: 16.w),
      CustomPickerPhoto(
        title: '证件反面',
        maxCount: 1,
        imagesList: controller.idPicBackList,
        titleTextStyle: TextStyle(
          fontSize: 14.sp,
          height: 1.2,
          fontWeight: FontWeight.w500,
          color: const Color(0xff262F38),
        ),
      ).paddingSymmetric(horizontal: 16.w),
    ];
    return ListView(children: [
      Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10.w),
        ),
        child: Column(
          children: children.joinWith(Divider(
            height: 1.w,
            color: const Color(0xffECEEF3),
          )),
        ),
      ),
      AppGaps.vGap10,
      _buildComment(),
      AppGaps.vGap10,
      _buildBottom(),
    ]);
  }

  Widget _buildPic(String url) {
    return Container(
      margin: EdgeInsets.only(top: 10.w),
      alignment: Alignment.centerLeft,
      height: 90.w,
      width: 144.w,
      color: _blue,
      child: Image.network(url),
    );
  }

  Widget _buildBottom() {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 5.w),
      child: InkWell(
        onTap: () {},
        child: Container(
          padding: EdgeInsets.symmetric(vertical: 9.w),
          decoration: BoxDecoration(
            color: _blue,
            borderRadius: BorderRadius.circular(44.w),
          ),
          alignment: Alignment.center,
          child: Text(
            '更新基本信息',
            style: TextStyle(
              fontSize: 16.w,
              color: Colors.white,
            ),
          ),
        ),
      ),
    );
  }

  Widget _buildAcknowledge() {
    return Container(
      decoration: BoxDecoration(color: const Color(0xFFF7F7F7), borderRadius: BorderRadius.circular(7.w)),
      padding: EdgeInsets.all(12.w),
      margin: EdgeInsets.all(13.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '实名制须知',
            style: TextStyle(fontSize: 14.w),
          ),
          Text(
            '1、请确保身份证照片清晰可认，严禁PS，否则将由您本人承担相应的法律后果。',
            style: _style,
          ),
          Text(
            '2、实名认证成功后，将无法修改和删除实名信息，请谨慎填写。',
            style: _style,
          ),
          Text(
            '3、我们将尽快审核您提交的信息，处理完成后您将会收到系统通知。',
            style: _style,
          ),
        ].joinWith(AppGaps.vGap10),
      ),
    );
  }

  Widget _buildComment() {
    return Text(
      '注：一年只允许修改一次',
      style: TextStyle(color: const Color(0xFFFC9900), fontSize: 14.w),
    );
  }
}
